<template>
  <div>
    <el-container class="con">
      <el-aside width="200px">
        <el-menu
          class="el-menu-vertical-demo"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
          unique-opened
        >
          <el-menu-item index="/index/home">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <!-- 动态侧边栏 -->
          <div v-for="item in userInfo.menus" :key="item.id">
            <el-menu-item v-if="!item.children" :index="item.url">{{
              item.title
            }}</el-menu-item>
            <!-- 目录 -->
            <el-submenu :index="item.id + ''" v-else>
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{ item.title }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  v-for="i in item.children"
                  :key="i.id"
                  :index="i.url"
                  >{{ i.title }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          </div>
          <!-- <el-submenu
            v-for="item in infopid"
            :key="item.id"
            :index="item.id.toString()"
          >
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.title }}</span>
            </template>
            <el-menu-item-group v-for="i in item.children" :key="i.id">
              <el-menu-item :index="'/index/' + i.url">{{
                i.title
              }}</el-menu-item>
            </el-menu-item-group>
          </el-submenu> -->
          <!-- <el-menu-item-group v-for="i in noinfopid" :key="i.id">
            <el-menu-item :index="'/index/' + i.url">{{
              i.title
            }}</el-menu-item>
          </el-menu-item-group> -->
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-row :gutter="20">
            <el-col :span="3" :offset="18">{{ userInfo.username }}</el-col>
            <el-col :span="2"
              ><el-button type="text" @click="logout"
                >退出登录</el-button
              ></el-col
            >
          </el-row>
        </el-header>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: 'home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <router-view class="view"> </router-view
        ></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
export default {
  data() {
    return {
      infopid: [],
      noinfopid: [],
    };
  },
  computed: {
    ...mapGetters({
      userInfo: "userInfo",
    }),
  },
  methods: {
    ...mapActions({
      changeUserInfo: "changeUserInfo",
    }),
    logout() {
      this.changeUserInfo({});
      this.$router.replace("/login");
    },
  },
  mounted() {
    // let infopid = this.userInfo.menus.filter((item) => item.pid == 0);
    // let noinfopid = this.userInfo.menus.filter((item) => item.pid != 0);
    // // console.log(noinfopid);
    // this.infopid = infopid;
    // this.noinfopid = noinfopid;
  },
};
</script>

<style scoped lang="less">
@import "../../less/index.less";
.con {
  height: 100vh;
}
.el-aside,
.el-menu-vertical-demo,
.el-menu-item-group {
  background: @primaryIndex;
}
.el-header,
.el-menu-item:focus,
.el-menu-item:hover,
/deep/ .el-submenu__title:hover {
  background: @indexHeader;
}
.view {
  margin-top: 20px;
}
.el-row {
  line-height: 60px;
  text-align: center;
}
// div{
//   background-color: #92d192
// }
</style>
